Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default #39

Merged
merged 5 commits into from
Jun 24, 2023
Merged

Default #39

merged 5 commits into from
Jun 24, 2023

Conversation

greyblake
Copy link
Owner

@greyblake greyblake commented Jun 24, 2023

Fixes #36

This PR allow deriving Default like it was proposed in issue #36

#[nutype(
    validate(min = 0.0, max = 100.0)
    default = 50.0
)]
#[derive(Default)]
pub struct Percent(f64)

TODO

  • parsing with attribute Default and generating proper Default implementation
  • Unit tests
  • Make sure that: default = and derive(Default) are rather both present or both absent. Otherwise show compilation error
  • UI test
  • Documentation
    • README
    • lib.rs

// satisfy the validation rules.
// For this purpose we generate a unit test to verify this at run time.
let unit_test = if has_validation {
#[cfg(not(feature = "nutype_test"))]
Copy link
Owner Author

@greyblake greyblake Jun 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is becoming a comment pattern, so consider coming up with a macro rule. E.g.

if_feature!("nutype_test",
    then: quote!("Feature is ON"),
    else: quote!("Feature is OFF"),
)

@greyblake greyblake merged commit ee8d8ee into master Jun 24, 2023
@greyblake greyblake deleted the default branch June 24, 2023 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Feature request: enable setting custom default values
1 participant